from django.forms import ModelForm, CharField, RegexField
from olwidget.widgets import EditableMap
from webmapper import models

class RouteUploadForm(ModelForm):
    class Meta:
        model = models.Route
        fields = ('title', 'caption', 'long_caption', 'private')

class KmlLayerUploadForm(ModelForm):
    unique_name = RegexField(regex=r'^[A-Za-z0-9][A-Za-z0-9_]*$', error_message="The unique name must start with a letter or number, and can only contain letters, numbers and underscore characters.")
    class Meta:
        model = models.StaticMapLayer
        fields = ('unique_name', 'title', 'kml_file', 'tags', 'map_keys')

class MapForm(ModelForm):
    unique_name = RegexField(regex=r'^[A-Za-z0-9][A-Za-z0-9_]*$', error_message="The unique name must start with a letter or number, and can only contain letters, numbers and underscore characters.")
    center = CharField(widget=EditableMap())
    class Meta:
        model = models.Map
        fields = ('unique_name', 'title', 'caption', 'static_layers', 'dynamic_layers', 'zoom', 'center')

class MapKeyForm(ModelForm):
    unique_name = RegexField(regex=r'^[A-Za-z0-9][A-Za-z0-9_]*$', error_message="The unique name must start with a letter or number, and can only contain letters, numbers and underscore characters.")
    class Meta:
        model = models.MapKey
        fields = ('unique_name', 'title', 'description', 'graphic')
